<!-- components/ImagePreview.vue -->
<template>
  <view class="image-preview" v-if="visible" @click="closePreview">
    <image :src="imageSrc" mode="aspectFit" class="preview-image" />
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
  imageSrc: {
    type: String,
    required: true,
  },
  visible: {
    type: Boolean,
    default: false,
  }
})

const emit = defineEmits(['update:visible'])

const closePreview = () => {
  uni.navigateBack(-1)
  emit('update:visible', false)
}
</script>

<style scoped>
.image-preview {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.8);
  justify-content: center;
  align-items: center;
  display: flex;
}

.preview-image {
  max-width: 100%;
  width: 100%;
  height: 100%;
  max-height: 100%;
}
</style>
